import { useSettingStore } from '@/store/modules/setting.ts'
import { getLocalStorage } from '@/utils/localStorage'

function isEqual(obj1: ObjIndex, obj2: ObjIndex) {
  const arr1 = Object.keys(obj1).sort()
  const arr2 = Object.keys(obj2).sort()
  if (arr1.length !== arr2.length) return false
  return arr1.every((item) => arr2.includes(item))
}
export const config: LayoutConfig = {
  Title: 'XuAdmin',
  Theme: 'default',
  Grey: false,
  Weak: false,
  HideTabs: false,
  DarkMode: false,
  Layout: 'left',
  Language: 'cn',
  ShowModel: 'card',
  ShowLogo: true,
  sidebarCollapse: false,
}

// 初始化一些配置
export function initConfig() {
  const { layoutConfig, resetLayoutConfig, setLayoutProps } = useSettingStore()
  if (!isEqual(config, getLocalStorage('layoutConfig'))) {
    resetLayoutConfig()
  } else {
    setLayoutProps('Theme', layoutConfig.Theme)
    setLayoutProps('DarkMode', layoutConfig.DarkMode)
  }
}
